﻿cmake_minimum_required(VERSION 3.0)

SET(PRODUCT_NAME app)

SET(CPP_HDRS
)

# Header files that need moc'd
SET(MOC_HDRS
    src/mainwindow.h
)

# Qt UI files
SET(UI_FILES
    ui/mainwindow.ui
)

#Windows的资源文件
set(RC_FILES
    #my.rc
)

set(RES_FILES
   ui/main.qrc
	#resource/icons/action_icons.qrc
)

QT5_ADD_RESOURCES( RES_SRCS ${RES_FILES} )

QT5_WRAP_UI( UI_HDRS ${UI_FILES} )

QT5_WRAP_CPP(MOC_SRCS ${MOC_HDRS})

SOURCE_GROUP("auto generated files" FILES ${MOC_SRCS} ${UI_HDRS} ${RES_SRCS})
SOURCE_GROUP("ui" FILES ${UI_FILES} ${RES_FILES})

SET(PRODUCT_FILES
	${RC_FILES}
	${RES_SRCS}
    ${MOC_SRCS}
    ${UI_HDRS}
    src/main.cpp
    src/mainwindow.cpp
    ${CPP_HDRS}
	${MOC_HDRS}
)

#SET(PRODUCT_DATA_FILES
    #data/axes.osgt
    #data/arial.ttf
#)

# 将当前项目路径添加到include，否则fatal error C1083: 无法打开包括文件: “ui_mainwindow.h”
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})

SET(WITH_CONSOLE 1)
IF(${WITH_CONSOLE})
    ADD_EXECUTABLE(${PRODUCT_NAME} ${PRODUCT_FILES})
ELSE(${WITH_CONSOLE})
    ADD_EXECUTABLE(${PRODUCT_NAME} WIN32 ${PRODUCT_FILES})
ENDIF(${WITH_CONSOLE})

SET_TARGET_PROPERTIES(${PRODUCT_NAME} PROPERTIES DEBUG_POSTFIX "${CMAKE_DEBUG_POSTFIX}")

#链接Qt静态库
qt5_use_modules(${PRODUCT_NAME} Gui Core OpenGL)

TARGET_LINK_LIBRARIES(${PRODUCT_NAME}
	osgQOpenGL
)

SET_TARGET_PROPERTIES(${PRODUCT_NAME} PROPERTIES 
    ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${PROJECT_BINARY_DIR}/lib"
    ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${PROJECT_BINARY_DIR}/lib"
    LIBRARY_OUTPUT_DIRECTORY_DEBUG "${PROJECT_BINARY_DIR}/lib"
    LIBRARY_OUTPUT_DIRECTORY_RELEASE "${PROJECT_BINARY_DIR}/lib"
    RUNTIME_OUTPUT_DIRECTORY_DEBUG "${PROJECT_BINARY_DIR}/bin"
    RUNTIME_OUTPUT_DIRECTORY_RELEASE "${PROJECT_BINARY_DIR}/bin"
	DEBUG_POSTFIX "d"
	RELEASE_POSTFIX "")

# 设置工作目录
SET_TARGET_PROPERTIES(${PRODUCT_NAME} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
	
# 设置工程调试环境变量PATH目录(最终影响项目属性-配置属性-调试-环境)，这样不会影响系统的环境变量PATH，只对当前项目起作用(VS_DEBUGGER_ENVIRONMENT需要CMake最低3.13)
SET(DLL_PATH "PATH=%PATH%" "${OSG_DIR}/bin;${OSGEARTH_DIR}/bin;${3rd_BIN_DIR}")
SET(DLL_PATH ${DLL_PATH} "${_qt5Widgets_install_prefix}/bin")
#MESSAGE(${_qt5Widgets_install_prefix})
SET_TARGET_PROPERTIES(${PRODUCT_NAME} PROPERTIES VS_DEBUGGER_ENVIRONMENT "${DLL_PATH}")

INSTALL(TARGETS ${PRODUCT_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
#INSTALL(FILES ${PRODUCT_DATA_FILES} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin/data)